package com.puti.doctor.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.puti.doctor.domian.HospitalDoctorInfo;
import com.puti.doctor.service.IHospitalDoctorInfoService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.puti.common.log.annotation.Log;
import com.puti.common.log.enums.BusinessType;
import com.puti.common.security.annotation.PreAuthorize;

import com.puti.common.core.web.controller.BaseController;
import com.puti.common.core.web.domain.AjaxResult;
import com.puti.common.core.utils.poi.ExcelUtil;
import com.puti.common.core.web.page.TableDataInfo;

/**
 * 医院-医生-个人信息 医院-医生-个人信息Controller
 * 
 * @author puti
 * @date 2021-04-20
 */
@CrossOrigin
@RestController
@RequestMapping("/info")
public class HospitalDoctorInfoController extends BaseController
{
    @Autowired
    private IHospitalDoctorInfoService hospitalDoctorInfoService;

    /**
     * 查询医院-医生-个人信息 医院-医生-个人信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HospitalDoctorInfo hospitalDoctorInfo)
    {
        startPage();
        List<HospitalDoctorInfo> list = hospitalDoctorInfoService.selectHospitalDoctorInfoList(hospitalDoctorInfo);
        return getDataTable(list);
    }

    @GetMapping("/listname")
    public List<HospitalDoctorInfo> doctorname(String doctorName)
    {
        List<HospitalDoctorInfo> doctor = hospitalDoctorInfoService.selectHospitalDoctorInfoListname(doctorName);
        return doctor;
    }
    //时间正序
    @GetMapping("/timeorder")
    public TableDataInfo listtiem(@RequestParam(value = "doctorName",required = false) String doctorName)
    {
        startPage();
        List<HospitalDoctorInfo> list = hospitalDoctorInfoService.selectHospitalDoctorInfoListtiem(doctorName);
        return getDataTable(list);
    }
    /**
     * 导出医院-医生-个人信息 医院-医生-个人信息列表
     */

    @Log(title = "医院-医生-个人信息 医院-医生-个人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalDoctorInfo hospitalDoctorInfo) throws IOException
    {
        List<HospitalDoctorInfo> list = hospitalDoctorInfoService.selectHospitalDoctorInfoList(hospitalDoctorInfo);
        ExcelUtil<HospitalDoctorInfo> util = new ExcelUtil<HospitalDoctorInfo>(HospitalDoctorInfo.class);
        util.exportExcel(response, list, "医院-医生-个人信息 医院-医生-个人信息数据");
    }

    /**
     * 获取医院-医生-个人信息 医院-医生-个人信息详细信息
     */
    //根据ID查询个人信息详细信息
    @GetMapping("/detailed")
    public HospitalDoctorInfo getInfo(Long doctorId)
    {
        return hospitalDoctorInfoService.selectHospitalDoctorInfoById(doctorId);
    }

    /**
     * 新增医院-医生-个人信息 医院-医生-个人信息
     */

    @Log(title = "医院-医生-个人信息 医院-医生-个人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalDoctorInfo hospitalDoctorInfo)
    {
        return toAjax(hospitalDoctorInfoService.insertHospitalDoctorInfo(hospitalDoctorInfo));
    }

    /**
     * 修改医院-医生-个人信息 医院-医生-个人信息
     */

//    @Log(title = "医院-医生-个人信息 医院-医生-个人信息", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody HospitalDoctorInfo hospitalDoctorInfo)
//    {
//        return toAjax(hospitalDoctorInfoService.updateHospitalDoctorInfo(hospitalDoctorInfo));
//    }
    @Log(title = "医院-医生-个人信息 医院-医生-个人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalDoctorInfo hospitalDoctorInfo)
    {
        return toAjax(hospitalDoctorInfoService.updateHospitalDoctorInfo(hospitalDoctorInfo));
    }

    /**
     * 删除医院-医生-个人信息 医院-医生-个人信息
     */
    @Log(title = "医院-医生-个人信息 医院-医生-个人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{doctorIds}")
    public AjaxResult remove(@PathVariable Long[] doctorIds)
    {
        return toAjax(hospitalDoctorInfoService.deleteHospitalDoctorInfoByIds(doctorIds));
    }
}
